import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/utils/x_load_svg.dart';

///
/// 优化的图片按钮widget - 添加缓存和性能优化
///
class SvgButtonWidget extends StatelessWidget {
  final String iconName;
  final Color color;
  final VoidCallback? onPressed;

  const SvgButtonWidget({
    super.key,
    required this.iconName,
    this.color = Colors.black,
    this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      child: IconButton(
        onPressed: onPressed,
        icon: XSvgImage.load(
          iconName,
          width: 28,
          height: 28,
          color: color,
        ),
        style: ButtonStyle(
          padding: WidgetStateProperty.all(EdgeInsets.zero),
          // 添加点击效果优化
          overlayColor: WidgetStateProperty.resolveWith<Color?>(
            (Set<WidgetState> states) {
              if (states.contains(WidgetState.pressed)) {
                return Colors.grey.withValues(alpha: 0.1);
              }
              return null;
            },
          ),
        ),
      ),
    );
  }
}
